package com.dwsoft.service;

import com.dwsoft.mapper.IDataKpiMapper;
import com.dwsoft.mapper.IWordTempleteMapper;
import com.dwsoft.pojo.WordTempleteDO;
import com.dwsoft.word.ElementContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import word.w2004.Document2004;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Map;

/**
 * @author sqw
 * @version 1.0
 * @description 生产word服务
 * @ClassName BaseWordServiceImpl
 * @Date 2020/8/5
 * @since jdk1.8
 */
@Service("wordService")
public class WordServiceImpl extends IWordService {

    @Autowired
    private ElementContext paragraphContext;

    @Resource
    private IWordTempleteMapper wordTempleteMapper;

    @Override
    public String generateWord(String id,Map<String,String> params) throws Exception {
        //1、获取模板主配置
        WordTempleteDO wordTempleteDO =  wordTempleteMapper.getTemplete(id);
        Document2004 document2004 = null;
        try {
            document2004 = paragraphContext.xmlToWord(wordTempleteDO.getTempleteXml(),params);
        } catch (IOException e) {
            e.printStackTrace();
        }
        this.document2004Local.set(document2004);
        return this.saveFile();
    }

    @Override
    public String generateWord(String id) throws Exception {
        return generateWord(id,null);
    }
}